package com.atguigu.daijia.dispatch.controller;

import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.dispatch.service.NewOrderService;
import com.atguigu.daijia.model.vo.dispatch.NewOrderTaskVo;
import com.atguigu.daijia.model.vo.order.NewOrderDataVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Tag(name = "司机新订单接口管理")
@RestController
@RequestMapping("/dispatch/newOrder")
@SuppressWarnings({"unchecked", "rawtypes"})
@RequiredArgsConstructor
public class NewOrderController {

    private final NewOrderService newOrderService;

    /**
     * 添加并启动新订单定时任务
     * @param newOrderTaskVo
     * @return
     */
    @Operation(summary = "添加并启动新订单定时任务")
    @PostMapping("/addAndStartTask")
    public Result<Long> addAndStartTask(@RequestBody NewOrderTaskVo newOrderTaskVo) {
        Long jobId = newOrderService.addAndStartTask(newOrderTaskVo);
        return Result.ok(jobId);
    }

    /**
     * 查询司机临时队列中的最新订单数据
     * @return
     */
    @Operation(summary = "查询司机临时队列中的最新订单数据")
    @GetMapping("/findNewOrderQueueData/{driverId}")
    public Result<List<NewOrderDataVo>> findNewOrderQueueData(@PathVariable("driverId") Long driverId) {
        List<NewOrderDataVo> list = newOrderService.findNewOrderQueueData(driverId);
        return Result.ok(list);
    }

    /**
     * 清空司机临时队列中的订单数据
     * @param driverId
     * @return
     */
    @Operation(summary = "清空司机临时队列中的订单数据")
    @GetMapping("/clearNewOrderQueueData/{driverId}")
    public Result<Boolean> clearNewOrderQueueData(@PathVariable("driverId") Long driverId) {
        Boolean result = newOrderService.clearNewOrderQueueData(driverId);
        return Result.ok(result);
    }
}

